package com.zdxf.controller;


import com.zdxf.conf.Constant;
import com.zdxf.domain.UpdatePasswordDTO;
import com.zdxf.domain.UserDO;
import com.zdxf.domain.UserRoleDO;
import com.zdxf.param.RoleParam;
import com.zdxf.param.UserParam;
import com.zdxf.service.impl.UserServiceImpl;
import com.zdxf.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@Api(tags = "用户角色权限管理")
public class UserController {

    @Autowired
    private UserServiceImpl userService;

    Result result = Constant.RESULT_EMPTY;

    /**
     * 角色列表不分页
     */
    @ApiOperation(value = "角色列表不分页", notes = "角色列表不分页")
    @GetMapping("/getAllRoles")
    public Object getAllRoles() {
        return userService.getAllRoles();
    }

    /**
     * 角色列表
     */
    @ApiOperation(value = "角色列表", notes = "角色列表")
    @PostMapping("/listRole")
    public Object listRole(@RequestBody RoleParam roleParam) {
        return userService.listRole(roleParam);
    }

    /**
     * 新增角色
     */
    @ApiOperation(value = "新增角色", notes = "新增角色")
    @PostMapping("/addRole")
    public Object addRole(@RequestBody UserRoleDO userRoleDO) {
        return userService.addRole(userRoleDO);
    }

    /**
     * 修改角色
     */
    @ApiOperation(value = "修改角色", notes = "修改角色")
    @PutMapping("/updateRole")
    public Object updateRole(@RequestBody UserRoleDO userRoleDO) {
        return userService.updateRole(userRoleDO);
    }

    /**
     * 删除角色
     */
    @DeleteMapping("/deleteRole")
    @ApiOperation(value = "删除角色", notes = "删除角色")
    public Object deleteRole(@RequestParam Long roleId) {
        return userService.deleteRole(roleId);
    }

    /**
     * 删除角色
     */
    @GetMapping("/getUseRole")
    @ApiOperation(value = "获取在使用角色的用户", notes = "获取在使用角色的用户")
    public Object getUseRole(@RequestParam Long roleId) {
        return userService.getUseRole(roleId);
    }

    /**
     * 用户列表
     */
    @ApiOperation(value = "用户列表", notes = "用户列表")
    @PostMapping("/userList")
    public Object userList(@RequestBody UserParam userParam) {
        return userService.userList(userParam);
    }

    /**
     * 新增用户
     */
    @ApiOperation(value = "新增角色", notes = "新增角色")
    @PostMapping("/addUser")
    public Object addUser(@RequestBody UserDO userDO) {
        return userService.addUser(userDO);
    }

    /**
     * 编辑用户
     */
    @ApiOperation(value = "编辑用户", notes = "编辑用户")
    @PutMapping("/updateUser")
    public Object updateUser(@RequestBody UserDO userDO) {
        return userService.updateUser(userDO);
    }

    /**
     * 用户详情
     */
    @ApiOperation(value = "用户详情", notes = "用户详情")
    @GetMapping("/getInfo")
    public Object getInfo(@RequestHeader("Authorization") String token) {
        token = token.substring(7);
        return userService.getInfo(token);
    }
    /**
     * 用户详情
     */
    @ApiOperation(value = "编辑用户", notes = "编辑用户")
    @PostMapping("/updateUserInfo")
    public Object updateUserInfo(@RequestBody UserDO userDO) {
        return userService.updateUser(userDO);
    }
    @PostMapping("/updatePassword")
    @ApiOperation(value = "修改密码", notes = "修改密码")
    public Object updatePassword(@RequestBody UpdatePasswordDTO updatePasswordDTO) {
        return userService.updatePassword(updatePasswordDTO);
    }
}
